package com.kizuki.controllor;

import com.kizuki.design.factory.PayFactory;
import com.kizuki.design.factory.PayStrategy;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
public class FactoryController {

    @Autowired
    PayFactory payFactory;

    @GetMapping("/factory/{payName}/{money}")
    public double discountPay(@PathVariable String payName, @PathVariable Long money){
        PayStrategy strategy = payFactory.getStrategy(payName);
        double payMoney = strategy.discountPayMoney(money);
        log.info("策略为:{}, 原价为:{}, 折扣价为:{}", payName, money, payMoney);
        return payMoney;
    }
}
